/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package carrello.impl.boundary.registereduser;

import carrello.impl.boundary.AbstractUI;
import carrello.model.association.Invoice;
import carrello.model.entities.User;
import java.util.LinkedList;
import java.util.List;

/**
 *
 * @author mepcotterell
 */
public class MyAccountUI extends AbstractUI {
    private User user;
    private LinkedList<LinkedList<String>> invoices;
    
    public User getUser () {
        return user;
    }
    
    public LinkedList<LinkedList<String>> getinvoices () {
        return invoices;
    }

    public String execute()
    {
        if (!getSessionIsLoggedIn()) {
            return LOGIN;
        }
        String username = getSessionUsername ();
        user = User.getUserByUserName(username);
        
        List<Invoice> inv = Invoice.getAllInvoicesByUserId ( user.getUserId());
        if ( inv.size() == 0 )
            invoices = null;
        else
        {
        invoices = new LinkedList<LinkedList<String>> ();
        LinkedList<String> param;
        
        for ( Invoice v: inv ) {
            param = new LinkedList<String> ();
            param.add (v.getProductname());
            param.add (String.valueOf(v.getQuantity()));
            param.add (v.getCost());
            double transaction = (Double.valueOf(v.getCost())) * v.getQuantity();
            param.add (String.valueOf(transaction));
            if ( v.getStatus() == '0' )
                param.add ("Processing");
            else
                param.add ("Shipped");
            param.add (v.getPurchase_date().toString());
            invoices.add (param);            
        }
        }
        return INPUT;
        
    }
 
}